package cn.itcast.nio.c1;

import java.nio.ByteBuffer;

public class TestByteBufferRead {
    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(10);
        buffer.put(new byte[]{'a','b','c','d'});
        buffer.flip();

        //reward 从头开始读
//        buffer.get(new byte[4]);
//        debugAll(buffer);
//        buffer.rewind();
//        System.out.println(buffer.get());

        // mark & reset
        // mark 做一个标记,记录position位置,reset 是将 position 重置到mark的位置

//        System.out.println((char) buffer.get());
//        System.out.println((char) buffer.get());
//        buffer.mark();//加标记,索引2的位置
//        System.out.println((char) buffer.get());
//        System.out.println((char) buffer.get());
//        buffer.reset();//将position重置到索引2
//        System.out.println((char) buffer.get());
//        System.out.println((char) buffer.get());

        // get(i)
        // 根据索引找 不会改变position
        System.out.println((char) buffer.get(3));
        System.out.println(buffer.position());
    }
}
